/*
 * @Descripttion: 
 * @version: 
 * @Author: ChenXiang
 * @Date: 2021-04-28 22:25:00
 * @LastEditors: ChenXiang
 * @LastEditTime: 2021-04-29 10:02:30
 */
const path = require('path');
const fs = require('fs-extra');
const chalk = require('chalk');

module.exports = function (creator, options, callback) {
  const { name, description, author, gitUrl } = options;
  // 获取当前命令的执行目录，注意和项目目录区分
  const cwd = process.cwd();
  // 项目目录
  const projectPath = path.join(cwd, name);
  // 获取自定义输入的值进行替换
  creator.copy('../template', path.join(projectPath));
  creator.delete(`../${name}/packagejson`);
  creator.copyTpl('packagejson', path.join(projectPath, `../${name}/package.json`), {
    name,
    description,
    author,
    gitUrl
  });
  creator.fs.commit(() => {
    console.log();
    console.log(`${chalk.grey(`创建项目: ${name}`)} ${chalk.green('✔ ')}`);
    callback();
  });
}